Visual Basic (Declaration) | |
---|---|
Public Overloads Function Run( _ ByVal ParamArray moreArguments() As String _ ) As Integer |
C# | |
---|---|
public int Run( params string[] moreArguments ) |
Parameters
- moreArguments
Library/Library.Test/TestProcessRunner.cs
C# | Copy Code |
---|---|
using (ProcessRunner runner = new ProcessRunner("cmd.exe")) { StringWriter wtr = new StringWriter(); StringWriter err = new StringWriter(); ProcessOutputEventHandler handler = delegate(object o, ProcessOutputEventArgs e) { if (e.Error) err.WriteLine(e.Data); else wtr.WriteLine(e.Data); }; runner.OutputReceived += handler; Assert.AreEqual(0, runner.Run("/C", "dir", "/b", "/on", "/ad-h-s", "c:\\")); Assert.AreEqual(String.Empty, err.ToString()); Assert.AreNotEqual(0, runner.PID); StringReader rdr = new StringReader(wtr.ToString()); List<DirectoryInfo> rootdirs = new List<DirectoryInfo>(new DirectoryInfo("C:\\").GetDirectories()); rootdirs.Sort(delegate(DirectoryInfo x, DirectoryInfo y) { return StringComparer.OrdinalIgnoreCase.Compare(x.Name, y.Name); }); foreach (DirectoryInfo di in rootdirs) { if ((di.Attributes & (FileAttributes.Hidden | FileAttributes.System)) != 0) continue; Assert.AreEqual(di.Name, rdr.ReadLine()); } Assert.AreEqual(null, rdr.ReadLine()); } |
VB.NET | Copy Code |
---|---|
Using runner As New ProcessRunner("cmd.exe") Dim wtr As New StringWriter() Dim err As New StringWriter() Dim handler As ProcessOutputEventHandler = Function(o As Object, e As ProcessOutputEventArgs) Do If e.[Error] Then err.WriteLine(e.Data) Else wtr.WriteLine(e.Data) End If End Function runner.OutputReceived += handler Assert.AreEqual(0, runner.Run("/C", "dir", "/b", "/on", "/ad-h-s", "c:\")) Assert.AreEqual([String].Empty, err.ToString()) Assert.AreNotEqual(0, runner.PID) Dim rdr As New StringReader(wtr.ToString()) Dim rootdirs As New List(Of DirectoryInfo)(New DirectoryInfo("C:\").GetDirectories()) rootdirs.Sort(Function(x As DirectoryInfo, y As DirectoryInfo) Do Return StringComparer.OrdinalIgnoreCase.Compare(x.Name, y.Name) End Function) For Each di As DirectoryInfo In rootdirs If (di.Attributes And (FileAttributes.Hidden Or FileAttributes.System)) <> 0 Then Continue For End If Assert.AreEqual(di.Name, rdr.ReadLine()) Next Assert.AreEqual(Nothing, rdr.ReadLine()) End Using |
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7
Reference
ProcessRunner ClassProcessRunner Members
Overload List